package lzy.units;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class BCryptUtil {

    private static final BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();

    /**
     * 将明文字符串换为BCrypt哈希值
     *
     * @param str 明文
     * @return BCrypt哈希值
     */
    public static String encodeString(String str) {
        return encoder.encode(str);
    }

    /**
     * 验证明文与BCrypt哈希值是否匹配
     *
     * @param str 明文
     * @param encode BCrypt哈希值
     * @return 如果匹配返回true，否则返回false
     */
    public static boolean checkMatches(String str, String encode) {
        return encoder.matches(str, encode);
    }


}
